Scatter plot is used with x-axis as the average balance and y as the num of credit cards and the color shows the status of the loan.

accounts$credit_cards[is.na(accounts$credit_cards)] <-0
accounts$loan_status[is.na(accounts$loan_status)] <- "none"
credit_cards = table(accounts$credit_cards)
accounts["avg_balance"] = (accounts$max_balance+accounts$min_balance)/2
fig <- plot_ly(
  data = accounts,
  x = ~avg_balance,
  y = ~credit_cards,
  alpha = 1,
  type = "scatter",
  text = ~paste("Loan: ", accounts$loan_status),
  color = accounts$loan_status
  
)
fig <- fig %>%
  layout(
    title = "credit cards vs. avg balance and loan status",
    yaxis = list(
      dtick = 1, 
      tick0 = 0, 
      tickmode = "linear"
  ))

fig
## No scatter mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode
## Warning: `arrange_()` is deprecated as of dplyr 0.7.0.
## Please use `arrange()` instead.
## See vignette('programming') for more help
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
import pandas as pd
import plotly.express as px
import matplotlib.pyplot as plt
accounts_py = pd.read_csv("./data/accounts_analytical.csv")
accounts_py.credit_cards.fillna(0, inplace=True)
accounts_py.loan_status.fillna("none", inplace=True)
accounts_py["avg_balance"] = (accounts_py.max_balance+accounts_py.min_balance)/2

credit0 = accounts_py[accounts_py["loan_status"]=="none"]
credit1 = accounts_py[accounts_py["loan_status"]=="current"]
credit2 = accounts_py[accounts_py["loan_status"]=="expired"]

plt.scatter(credit0.avg_balance, credit0.credit_cards, label="none")
plt.scatter(credit1.avg_balance, credit1.credit_cards, label="current")
plt.scatter(credit2.avg_balance, credit2.credit_cards, label="expired")
plt.legend()
plt.yticks([0,1,2])
## ([<matplotlib.axis.YTick object at 0x7fca812633d0>, <matplotlib.axis.YTick object at 0x7fca81259a90>, <matplotlib.axis.YTick object at 0x7fcaa0ce1d10>], <a list of 3 Text yticklabel objects>)
plt.xlabel("Avg balance")
plt.ylabel("Num of credit cards")
plt.title("credit cards vs. avg balance and loan status")
plt.show()